description "Datadog System Probe"

start on starting datadog-agent
stop on (runlevel [!2345] or stopping datadog-agent)

respawn
respawn limit 4 25
normal exit 0

# Logging to console from the agent is disabled since the agent already logs using file or
# syslog depending on its configuration. We make upstart log what the process still outputs in order
# to log panics/crashes to /var/log/upstart/datadog-agent.log
console log
env DD_LOG_TO_CONSOLE=false

# mount debugfs before start
pre-start script
  # Do not run if config file doesn't exist
  test -f <%= etc_dir %>/system-probe.yaml || { stop ; exit 0; }

  if [ -d /sys/kernel/debug ]; then
    if ! grep -qs '/sys/kernel/debug ' /proc/mounts; then
      mount -t debugfs none /sys/kernel/debug
    fi
  fi
end script

script
  exec <%= install_dir %>/embedded/bin/system-probe run --config=<%= etc_dir %>/system-probe.yaml --pid=<%= install_dir %>/run/system-probe.pid
end script

post-stop script
  rm -f <%= install_dir %>/run/system-probe.pid
end script
